// 引入axios组件
import axios from 'axios';
import qs from 'qs'; // 处理数据  qs.stringify(params)
import { checkRule } from '@/assets/js/public'; // 引入公共js文件
// import {productaxios,pro} from '@/assets/js/productaxios'
export default {
  data() {
    return {
      title: '', // 面包屑标题
      search: '',
      modal1: false, // 模态框显示开关，true显示   false不显示
      param: '', // 点击编辑、删除的时候对应操作的那个id
      putpage: '', // 存储页数
      columns7: [
        {
          title: 'id',
          width: 100,
          key: 'id',
          render: (h, params) => h('div', [h('strong', params.row.id)]),
        },
        {
          title: 'qq昵称',
          key: 'nickname',
          render: (h, params) => h('div', [h('strong', params.row.nickname)]),
        },
        {
          title: '性别',
          key: 'gender',
        },
        {
          title: '所在地',
          key: 'city',
        },
        {
          title: '出生年',
          key: 'year',
        },
        {
          title: '最后登陆时间',
          key: 'logintime',
        },
      ],
    };
  },
  created() {
    const self = this;
    this.$Spin.show();
    setTimeout(() => {
      this.$Spin.hide();
    }, 500);
    const spage = this.$route.query.page;
    const asearch = this.$route.query.search;
    axios({
      method: 'post',
      url: '/admin/user/userList',
      data: { page: spage, search: asearch },
    })
      .then((response) => {
        checkRule(response, self); // 检查是否有权限
        self.putpage = spage;
        self.$store.commit('getUserInfo', response.data);
      })
      .catch((response) => {
        console.log(response);
      });
  },
  // 用来获取VUEX中的文件
  computed: {
    data() {
      return this.$store.state.user.userlistshow;
    },
    page() {
      return this.$store.state.user.total;
    },
  },
  methods: {
    // 分页的钩子函数，当跳页的时候重新请求（将页码发给后台）
    getpage(page) {
      if (page == undefined) {
        page = 1;
      }
      this.putpage = page;
      const self = this;
      axios({
        method: 'post',
        url: '/admin/user/userList',
        data: {
          page,
          search: self.search,
        },
      })
        .then((response) => {
          self.$store.commit('getUserInfo', response.data);
        })
        .catch((response) => {
          console.log('请求失败');
        });
      this.$router.push({
        path: '/user', // 这是路由名称
        query: { page, search: self.search },
      });
    },
  },
};
